package com.minicat.server;

import java.io.IOException;

public class LagouServlet implements Servlet {
    @Override
    public void init() throws Exception {
        System.out.println("demo2 LagouServlet init()");
    }

    @Override
    public void destory() throws Exception {
        System.out.println("demo2 LagouServlet destory()");
    }

    @Override
    public void service(Request request, Response response) throws Exception {
        if ("GET".equalsIgnoreCase(request.getMethod())){
            doGet(request,response);
        }else{
            doPost(request,response);
        }
    }

    public void doGet(Request request,Response response) throws IOException {
        String content = "<h1> demo2 LagouServlet GET";
        response.output(HttpProtocolUtil.getHttp200(content.getBytes().length)+content);
    }

    public void doPost(Request request,Response response) throws IOException {
        String content = "<h1> demo2 LagouServlet POST";
        response.output(HttpProtocolUtil.getHttp200(content.getBytes().length)+content);
    }
}
